<template>
  <div class="app-container">
    <el-form
      :model="formInline"
      :inline="true"
      ref="ruleForm"
    >
      <el-form-item label="支付类型" prop="paymentIds">
        <el-select
          multiple
          v-model="formInline.paymentIds"
          collapse-tags
          placeholder="请选择支付类型"
        >
          <el-option
            v-for="item in paymentManageList"
            :label="item.paymentName"
            :value="item.paymentId"
            :key="item.paymentId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三方平台" prop="channelId">
        <el-select
          v-model="formInline.channelId"
          placeholder="请选择渠道类型"
          filterable
        >
          <el-option
            v-for="item in channelList"
            :label="item.channelName"
            :value="item.channelId"
            :key="item.channelId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商户号" prop="merchantCode">
        <el-input
          v-model="formInline.merchantCode"
          placeholder="请输入商户号码"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="渠道类型" prop="limitType">
        <el-select
          v-model="formInline.limitType"
          placeholder="请选择支付类型"
        >
          <el-option
            v-for="item in payEnum.PAY_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="层级类型" prop="levelIds">
        <el-select
          multiple
          v-model="formInline.levelIds"
          collapse-tags
          placeholder="请选择层级类型"
        >
          <el-option
            v-for="item in userLevelList"
            :label="item.name"
            :key="item.levelId"
            :value="item.levelId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="上下架状态" prop="status">
        <el-select
          v-model="formInline.status"
          placeholder="请选择上下架状态"
        >
          <el-option
            v-for="item in payEnum.ESCROWS_STATUS_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开关状态" prop="openStatus">
        <el-select
          v-model="formInline.openStatus"
          placeholder="请选择上下架状态"
        >
          <el-option
            v-for="item in payEnum.PAY_STATUS_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="应用端" prop="clientType">
        <el-select
          v-model="formInline.clientType"
          placeholder="请选择应用端"
        >
          <el-option
            v-for="item in payEnum.DEVICE_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="推荐状态" prop="recommendStatus">
        <el-select
          v-model="formInline.recommendStatus"
          placeholder="请选择推荐状态"
        >
          <el-option
            v-for="item in payEnum.RECOMMEND_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="置顶状态" prop="topStatus">
        <el-select
          v-model="formInline.topStatus"
          placeholder="请选择置顶状态"
        >
          <el-option
            v-for="item in payEnum.TOPPING_TYPE"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        :loading="$parent.loading"
        @click="onClickSearch"
      >
        搜索
      </el-button>
      <el-button
        @click="onClickResetForm('ruleForm')"
      >
        重置
      </el-button>
    </el-form>
  </div>
</template>


<script>

// constants
import { paySetType } from '@/router/payRoutes';

// services
import {
  getPaymentManageList,
  getPaymentManageChannelList,
} from '@/services/api/recharge';
import {
  getUserLevelList,
} from '@/services/api/userLevel';

// mixins
import { grid, constsLabel } from '@/build';

export default {
  name: 'receipt',
  components: {
  },
  mixins: [grid, constsLabel],
  data() {
    return {
      paySetType,
      formInline: {
        paymentIds: [],
        channelId: -1,
        merchantCode: null,
        limitType: -1,
        levelIds: [],
        status: -1,
        openStatus: -1,
        clientType: -1,
        recommendStatus: -1,
        topStatus: -1,
      },
      paymentManageList: [],
      channelList: [],
      userLevelList: [],
    };
  },
  computed: {
  },

  methods: {
    initRouteParams() {
      const { level } = this.$route.query;
      if (!level) return;
      this.formInline.levelIds = [Number(level)];
    },
    onClickSearch() {
      const {
        paymentIds,
        levelIds,
      } = this.formInline;
      this.$emit('on-filter', {
        ...this.formInline,
        paymentIds: paymentIds.length ? paymentIds.join(',') : '',
        levelIds: levelIds.length ? levelIds.join(',') : '',
      });
    },
    onClickResetForm(formName) {
      this.resetForm(formName);
      this.onClickSearch();
    },
  },
  created() {
    this.initRouteParams();
  },
  activated() {
    this.initRouteParams();
    this.onClickSearch();
  },
  mounted() {
    this.bindGet(getPaymentManageList, 'paymentManageList');
    this.bindGet(getPaymentManageChannelList, 'channelList', {
      format: (data) => {
        data.unshift({ channelId: -1, channelName: '全部' });
        return data;
      },
    });
    this.bindGet(getUserLevelList, 'userLevelList');
    this.getAll();
  },
};
</script>

<style lang="scss" scoped>
  .el-table-align-center {
    &.el-table {
      width: 100%;
      text-align: center !important;
      th {
        text-align: center !important;
      }
    }
  }

</style>
